home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / mystic.zip / TUTOR.PAS < prev   
Pascal/Delphi Source File  |  1986-03-21  |  9KB  |  328 lines

  1. { mystic pascal  tutorial PROGRAM }
  2.  
  3. PROGRAM tutor;
  4.  
  5. CONST
  6. lessoncount = 8;
  7. pi = 3.14159;
  8.  
  9. TYPE
  10. registers = RECORD
  11.         al,ah,bl,bh,cl,ch,dl,dh : char;
  12.         bp,si,di,ds,es,flags : integer
  13.         END;
  14.  
  15. VAR
  16. i, j, lesson : integer;
  17. a, b, c : real;
  18. regs : registers;
  19. seconds : integer;
  20. f : text;
  21.  
  22.  
  23.  
  24. PROCEDURE cls;
  25. BEGIN
  26. write( chr(4) )
  27. END;
  28.  
  29. PROCEDURE ten;
  30. VAR
  31. i : integer;
  32. BEGIN
  33. FOR i := 1 TO 10 DO
  34.         write(i);
  35. writeln
  36. END;
  37.  
  38. PROCEDURE bar ( count : integer );
  39. VAR
  40. i : integer;
  41. BEGIN
  42. WHILE count >= 10 DO
  43.         BEGIN
  44.         write('----------');
  45.         count := count - 10
  46.         END;
  47. FOR i := 1 TO count DO
  48.         write('-');
  49. writeln;
  50. END;
  51.  
  52. FUNCTION area ( radius : real ): real;
  53. BEGIN
  54. area := pi * sqr(radius)
  55. END;
  56.  
  57. PROCEDURE break;
  58. BEGIN
  59. regs.cl := chr(0);
  60. intr(226,regs)
  61. END;
  62.  
  63. PROCEDURE timer;
  64. LABEL 10, 99;
  65. VAR
  66. lastvalue : char;
  67. BEGIN
  68. lastvalue := chr(255);
  69. 10:
  70. break;
  71. IF (seconds <= 0) OR (seconds >= 60) THEN
  72.         BEGIN
  73.         writeln;
  74.         writeln('Timer is terminating.');
  75.         write('\ ');
  76.         GOTO 99
  77.         END;
  78. regs.ah := chr(44);
  79. intr(33,regs);
  80. WITH regs DO
  81.    IF ((ord(dh) MOD seconds) = 0) AND (dh <> lastvalue) THEN
  82.         BEGIN
  83.         lastvalue := dh;
  84.         ah := chr(2);
  85.         dl := chr(7);      {sound a tone}
  86.         intr(33,regs)
  87.         END;
  88. GOTO 10;
  89. 99:
  90. END;
  91.  
  92. PROCEDURE squares;
  93. VAR
  94. i : integer;
  95. BEGIN
  96. rewrite(f);
  97. writeln(f,'SQUARES TABLE  1 TO 50');
  98. writeln(f);
  99. FOR i := 1 TO 50 DO
  100.         BEGIN
  101.         write(f,i:3,sqr(i),'    ');
  102.         IF (i MOD 5) = 0 THEN writeln(f)
  103.         END;
  104. close(f)
  105. END;
  106.  
  107.  
  108. PROCEDURE menu;
  109. BEGIN
  110. writeln('------------------------ Lessons -------------------------');
  111. writeln('1  Introduction               5  Procedure Calls');
  112. writeln('2  Direct Mode                6  Floating Point ',
  113.         'Arithmetic');
  114. writeln('3  Assignments & Writeln      7  Multi-tasking');
  115. writeln('4  Dot Write Command          8  Printer & Disk Output');
  116. writeln;
  117. writeln('--------- Commands ----------');
  118. writeln('L(x)   select a lesson number');
  119. writeln('NEXT   go to the next lesson');
  120. writeln('AGAIN  redisplay last lesson');
  121. writeln('CLS    clear the screen');
  122. writeln
  123. END;
  124.  
  125. PROCEDURE l1;
  126. BEGIN
  127. writeln('Lesson 1  Introduction');
  128. writeln;
  129. writeln('Mystic Pascal is a complete programming system with a full');
  130. writeln('screen editor, incremental compiler and multi-tasking');
  131. writeln('operating system which runs on top of DOS.');
  132. writeln;
  133. writeln('This tutorial program will introduce you to the operation');
  134. writeln('of Mystic Pascal.  It will not teach you the Pascal');
  135. writeln('language.');
  136. writeln;
  137. writeln('Mystic Pascal Advanced Features');
  138. writeln('------ ------ -------- --------');
  139. writeln('1. Ultra-fast new compiler design');
  140. writeln('2. Supports full 640K of storage');
  141. writeln('3. Interactive Direct Mode');
  142. writeln('4. Multi-tasking support');
  143. writeln('5. Full screen editor talks to compiler');
  144. writeln('6. Help windows - F7, F9, F10');
  145. writeln;
  146. END;
  147.  
  148. PROCEDURE l2;
  149. BEGIN
  150. writeln('Lesson 2  Direct Mode');
  151. writeln;
  152. writeln('In the Direct Mode screen you can key in any Pascal');
  153. writeln('statement to be instantly executed.  The statement is');
  154. writeln('compiled by the incremental compiler and then it is');
  155. writeln('executed.  If it produced any output, this is displayed');
  156. writeln('on the screen.');
  157. writeln;
  158. writeln('The Direct Mode of Mystic Pascal works like a Basic');
  159. writeln('interpreter, but it is a TRUE COMPILER.');
  160. writeln;
  161. writeln('In Direct Mode you have access to all global variables,');
  162. writeln('procedures and functions.  Objects which are declared');
  163. writeln('locally within a procedure or function are not accessible.');
  164. END;
  165.  
  166. PROCEDURE l3;
  167. BEGIN
  168. writeln('Lesson 3  Assignments & Writeln');
  169. writeln;
  170. writeln('Note that I, J are global Integer variables.');
  171. writeln;
  172. writeln('Key in the following statements, following the \ prompt:');
  173. writeln;
  174. writeln('I := 75; WRITELN(I)');
  175. writeln;
  176. writeln('J := 100; WRITELN( I, J, I * J )');
  177. END;
  178.  
  179. PROCEDURE l4;
  180. BEGIN
  181. writeln('Lesson 4  Dot Write Command');
  182. writeln;
  183. writeln('Very often when working in Direct Mode, you will need');
  184. writeln('to display the value of some variables.  You may do this');
  185. writeln('with a Write or Writeln.  Mystic Pascal also provides a');
  186. writeln('short-cut.  The Dot Write Command allows you to display');
  187. writeln('one or more expressions, by just preceding them with a');
  188. writeln('period.');
  189. writeln;
  190. writeln('.I    is equivalent to    WRITE(I)');
  191. writeln('.5 * 20, 30 div 3     will display    100    10');
  192. writeln;
  193. writeln('The period must be the first character on the line and no');
  194. writeln('other Pascal statements may follow on that line.');
  195. writeln;
  196. writeln('Try this command now by displaying variables I and J.');
  197. END;
  198.  
  199. PROCEDURE l5;
  200. BEGIN
  201. writeln('Lesson 5  Procedure Calls');
  202. writeln;
  203. writeln('All Pascal programs are subdivided into subprograms');
  204. writeln('called procedures.  Each procedure performs some logical');
  205. writeln('purpose and should have a meaningful name.  To activate');
  206. writeln('a procedure, you just give its name.  This Tutor program');
  207. writeln('includes a procedure named TEN which simply displays the');
  208. writeln('numbers 1 through 10.  Type TEN now to activate it.');
  209. writeln;
  210. writeln('Procedures may also have parameter values passed to them.');
  211. writeln('The sample procedure BAR displays a line of dashes.  It');
  212. writeln('needs one parameter to indicate the number of dashes to');
  213. writeln('display.  Try it now by typing  BAR(25).');
  214. END;
  215.  
  216. PROCEDURE l6;
  217. BEGIN
  218. writeln('Lesson 6  Floating Point Arithmetic');
  219. writeln;
  220. writeln('The Tutor program has 3 global Real variables A, B, C.');
  221. writeln('You may experiment with floating point arithmetic using');
  222. writeln('these variables.');
  223. writeln;
  224. writeln('A := 45.3;  B := 2E-2');
  225. writeln('.A, B, A * B');
  226. writeln('.A + B:20:4      fixed-point output');
  227. writeln('.A >= B          comparison');
  228. writeln;
  229. writeln('There is also a Real function named AREA which computes');
  230. writeln('the area of a circle given its radius.  The parameter');
  231. writeln('must be a real number.');
  232. writeln;
  233. writeln('.AREA( 10.0 )');
  234. writeln('A := 50.0;   WRITELN( AREA(A) )');
  235. END;
  236.  
  237. PROCEDURE l7;
  238. BEGIN
  239. writeln('Lesson 7  Multi-tasking');
  240. writeln;
  241. writeln('The Mystic Pascal system is based on multi-tasking.');
  242. writeln('Your Pascal programs may have up to 100 procedures running');
  243. writeln('at the same time - Concurrent Procedures.  This capability');
  244. writeln('is useful for doing simulations and for real-time');
  245. writeln('programming, such as controlling an assembly line.');
  246. writeln;
  247. writeln('The Timer procedure in this Tutor program illustrates the');
  248. writeln('multi-tasking feature.  Timer constantly watches the PC');
  249. writeln('system clock and sounds a tone every few seconds.');
  250. writeln('You can determine the time interval between tones by');
  251. writeln('setting the integer variable SECONDS.');
  252. writeln;
  253. writeln('To start up Timer enter:');
  254. writeln;
  255. writeln('SECONDS := 10;  START( TIMER, ''TIMER'', 10)');
  256. writeln;
  257. writeln('Examine the System Display screen to see the Timer process');
  258. writeln('in the PCB table.  To change the interval, just store a new');
  259. writeln('number in SECONDS.  To stop Timer, set SECONDS to 0.');
  260. END;
  261.  
  262. PROCEDURE l8;
  263. BEGIN
  264. writeln('Lesson 8  Printer & Disk Output');
  265. writeln;
  266. writeln('The Assign procedure lets you fully control the routing');
  267. writeln('of output to the console, printer or a disk file.  The');
  268. writeln('Tutor program contains a procedure named SQUARES which');
  269. writeln('prints the squares of the numbers 1 to 50.  This report may');
  270. writeln('be routed to the console, printer or disk by Assign.');
  271. writeln('SQUARES sends its output to the text file variable F.');
  272. writeln;
  273. writeln('To route the report to the printer, type:');
  274. writeln('    ASSIGN( F, PRN );  SQUARES');
  275. writeln;
  276. writeln('To route it to a disk file, type:');
  277. writeln('    ASSIGN( F, ''SQ.TAB'' );  SQUARES');
  278. writeln;
  279. writeln('To route it to the console:');
  280. wr